package com.syf.kit.core.dao.impl;

import com.syf.kit.core.dao.SyfRdsDaoUtil;
import com.syf.kit.core.dao.mapper.MapperType;
import com.syf.kit.core.ds.impl.SyfDataSource;
import com.syf.kit.enums.DataSourceType;
import org.apache.ibatis.transaction.TransactionFactory;

import javax.sql.DataSource;

public class SyfSimpleRdsDaoUtilFactory extends SingleRdsDaoUtilsFactory {

    public SyfSimpleRdsDaoUtilFactory(SyfDataSource syfDataSource, boolean autocommit, MapperType mapperType) {
        super(syfDataSource, autocommit, mapperType);
    }

    public SyfSimpleRdsDaoUtilFactory(SyfDataSource syfDataSource, TransactionFactory dbTxFactory, boolean autocommit, MapperType mapperType) {
        super(syfDataSource, dbTxFactory, autocommit, mapperType);
    }

    @Override
    public SyfRdsDaoUtil buildSyfRdsDaoUtil() {
        return new SyfSimpleRdsDaoUtil(getSqlSessionFactory(), getMapperRegistry(), isAutoCommit(), getMapperType());
    }

    @Override
    public DataSource covertDbDataSource(SyfDataSource syfDataSource) {
        if (!DataSourceType.SINGLE.equals(syfDataSource.getDsType())) {
            throw new RuntimeException("非法调用，此处必须传入：SyfSingleDataSource");

        }

        return syfDataSource.getDefaultDataSource();
    }
}
